package com.wf.articleManagement.controller;

import com.wf.apicommons.entity.userManagement.UserInformation;
import com.wf.apicommons.utils.CommonResult;
import com.wf.apicommons.entity.articleManagement.ArticleDetails;
import com.wf.articleManagement.service.local.BlogRelatedService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 博客相关
 */
@RestController
@RequestMapping("/article")
@Slf4j
public class BlogRelatedController {


    /**
     * 博客service
     */
    @Autowired
    @Qualifier("blogRelatedServiceImpl")
    BlogRelatedService brs;



    /**
     * 添加文章
     * @param articleDetails
     * @return
     */
    @PostMapping(value = "/add")
    public CommonResult<String> addArticle(@RequestBody ArticleDetails articleDetails)
    {
        return brs.createArticle(articleDetails);
    }


    /**
     * 上传文件到腾讯云COS
     * @param file 文件
     * @param remarks 文件备注
     * @return 文件访问地址
     */
    @PostMapping("/fileUpload")
    public CommonResult<String> fileUpload(@RequestParam("file") MultipartFile file, @RequestParam("remarks") String remarks){
        return brs.fileUploadCos(file,remarks);
    }

    /**
     * 查询文章列表
     * @param param
     * @return
     */
    @PostMapping("/queryArticleList")
    public CommonResult<Map<String, Object>>  queryArticleList(@RequestBody Map<String,Object> param){
        return brs.queryArticleList(param);
    }

    /**
     * 查询指定文章详情
     * @param articleId 文章ID
     * @param isCompile 返回的文章内容是否需要编译
     * @return
     */
    @GetMapping("/queryBlogDetails/{articleId}/{isCompile}")
    public  CommonResult<Map<String,Object>> queryBlogDetails(@PathVariable("articleId") String articleId,@PathVariable("isCompile") boolean isCompile){
        return brs.queryBlogDetails(articleId,isCompile);
    }





    /**
     * 查询指定用户的文章列表
     * @param param
     * @return
     */
    @PostMapping(value = "/queryUserArticleList")
    public CommonResult<Map<String, Object>> querySpecifyUserArticleList(@RequestBody Map<String, Object> param) {
        return brs.querySpecifyUserArticleList(param);
    }

    /**
     * 删除指定文章
     * @param articleId
     * @return
     */
    @GetMapping(value = "/delete/{articleId}")
    public  CommonResult<String> deleteArticle(@PathVariable("articleId") String  articleId){
        return brs.deleteArticle(articleId);
    }

    /**
     * 修改指定文章
     * @param articleDetails
     * @return
     */
    @PostMapping(value = "/update")
    public  CommonResult<String> updateArticle(@RequestBody ArticleDetails  articleDetails){
        return brs.updateArticle(articleDetails);
    }
}


